package com.cl.short_video_java.web.client.concern;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.annotation.NoRepeatSubmit;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.pojo.VideoUserFollowed;
import com.cl.short_video_java.service.VideoUserFollowedService;
import com.cl.short_video_java.service.VideoUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 付
 * @Date 2024-11-24 10:54
 * @Version 1.0
 * @description
 * @since 1.0
 */

@RestController
@RequestMapping("/client/concern")
public class ClientConcernController {

	private VideoUserService videoUserService;
	private VideoUserFollowedService followedService;

	public ClientConcernController(VideoUserService videoUserService, VideoUserFollowedService followedService) {
		this.videoUserService = videoUserService;
		this.followedService = followedService;
	}

	/**
	 * 获取用户关注列表
	 *
	 * @param type    1-关注，2-粉丝
	 * @param request
	 * @param current 当前页
	 * @return
	 */
	@GetMapping("/concern")
	@Login(issuer = Const.GRADE_USER)
	public Result getConcern(@RequestParam("type") Integer type, @RequestParam("current") Integer current, HttpServletRequest request) {
		Page<VideoUserFollowed> page = followedService.concern(type, current, request);
		return Result.success(page);
	}

	/**
	 * 关注-取消关注
	 *
	 * @param type    1-关注，0-取消关注
	 * @param uid     被关注的id
	 * @param request
	 * @return
	 */
	@GetMapping("/followed")
	@NoRepeatSubmit(lockTime = 3)
	public Result getFollowed(@RequestParam("type") Integer type, @RequestParam("uid") Integer uid, HttpServletRequest request) {
		followedService.followed(type, uid, request);
		return Result.success();
	}
}
